<%--
  Created by IntelliJ IDEA.
  User: dllo
  Date: 18/3/3
  Time: 上午10:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1 , user-scalable=no">
    <title>俱乐部列表</title>
    <link rel="stylesheet" href="../css/bootstrap.min.new.css"/>
    <link rel="stylesheet" href="../css/bootstrap-maizi.css"/>
</head>
<body>
<%
    if (request.getSession().getAttribute("success") != null) {
%>
<script>
    alert("成功!")

</script>
<%session.removeAttribute("success");}
    if (request.getSession().getAttribute("fail") != null){%>
<script>
    alert("失败!")
</script>

<%session.removeAttribute("fail");}%>
<!--导航-->
<nav class="navbar navbar-default">
    <div class="container">
        <!--小屏幕导航按钮和logo-->
        <div class="navbar-header">
            <button class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a href="userlist" class="navbar-brand">Changwan</a>
        </div>
        <!--小屏幕导航按钮和logo-->
        <!--导航-->
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li ><a href="userlist"><span class="glyphicon glyphicon-user"></span>&nbsp;&nbsp;用户管理</a></li>
                <li><a href="shoplist"><span class="glyphicon glyphicon-user"></span>&nbsp;&nbsp;商品管理</a></li>
                <li class="active"><a href="clublist"><span class="glyphicon glyphicon-user"></span>&nbsp;&nbsp;俱乐部管理</a></li>
                <li><a href="gamelist"><span class="glyphicon glyphicon-user"></span>&nbsp;&nbsp;比赛管理</a></li>
                <li><a href="masterlist"><span class="glyphicon glyphicon-user"></span>&nbsp;&nbsp;大师管理</a></li>
                <li><a href="orderlist"><span class="glyphicon glyphicon-user"></span>&nbsp;&nbsp;订单管理</a></li>
                <li><a href="photolist"><span class="glyphicon glyphicon-user"></span>&nbsp;&nbsp;晒图管理</a></li>
                <li><a href="commentlist"><span class="glyphicon glyphicon-user"></span>&nbsp;&nbsp;评论管理</a></li>

            </ul>
            <ul class="nav navbar-nav navbar-right">

                <li><a href="#bbs"><span class="glyphicon glyphicon-off"></span>&nbsp;&nbsp;退出</a></li>
            </ul>
        </div>
        <!--导航-->

    </div>
</nav>
<!--导航-->

<div class="container">
    <div class="row">
        <div class="col-md-2">
            <div class="list-group">
                <a href="clublist" class="list-group-item active">俱乐部管理</a>
                <a href="clubsearch" class="list-group-item">俱乐部搜索</a>
                <a href="" role="button" class="list-group-item" data-toggle="modal" data-target="#myModal">添加俱乐部</a>
            </div>
        </div>
        <div class="col-md-10">
            <div class="page-header">
                <h1>俱乐部管理</h1>
            </div>
            <ul class="nav nav-tabs">
                <li class="active">
                    <a href="clublist">俱乐部列表</a>
                </li>
                <li>
                    <a href="clubsearch">俱乐部搜索</a>
                </li>
                <li>
                    <a href="" role="button" data-toggle="modal" data-target="#myModal">添加俱乐部</a>
                </li>
            </ul>
            <table class="table">
                <thead id="head">
                <tr>
                    <th>ID</th>
                    <th>俱乐部名称</th>
                    <th>俱乐部简介</th>
                    <th>俱乐部图片</th>
                    <th>俱乐部地址</th>
                    <th>俱乐部活动</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="user">

                </tbody>
            </table>
            <nav class="pull-right">
                <ul class="pagination">
                    <li class="disabled"><a href="#" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a>
                    </li>
                    <li class="active"><a href="#">1</a></li>
                    <li><a href="#">2 </a></li>
                    <li><a href="#">3 </a></li>
                    <li><a href="#">4 </a></li>
                    <li><a href="#">5 </a></li>
                    <li><a href="#">6 </a></li>
                    <li><a href="#"><span aria-hidden="true">&raquo;</span></a></li>
                </ul>
            </nav>
        </div>
    </div>
</div>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel"></h4>
            </div>
            <form action="/addclub" id="club" method="post" enctype="multipart/form-data">
                <div class="modal-body">

                    <div class="form-group">
                        <label for="addname">俱乐部名称</label>
                        <input type="text" id="addname" name="name" class="form-control" placeholder="俱乐部名称">
                    </div>
                    <div class="form-group">
                        <label for="addintro">俱乐部简介</label>
                        <input type="text" id="addintro" name="intro" class="form-control" placeholder="俱乐部简介">
                    </div>
                    <div class="form-group">
                        <label for="addpic">请选择图片</label>
                        <input type="file" id="addpic" name="file" class="form-control">
                    </div>
                    <div class="form-group">
                        <label for="addplace">俱乐部地址</label>
                        <input type="text" id="addplace" class="form-control" name="place" placeholder="俱乐部地址">
                    </div>
                    <div class="form-group">
                        <label for="addactivity">俱乐部活动</label>
                        <input type="text" id="addactivity" class="form-control" name="activity" placeholder="俱乐部活动">
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <input type="submit" class="btn btn-primary" id="sub">
                </div>
            </form>
        </div>
    </div>
</div>
<!--footer-->
<footer>
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <p>
                    Copyright&nbsp;©&nbsp;2017-2018&nbsp;&nbsp;www.changwan.com&nbsp;&nbsp;
                </p>
            </div>
        </div>
    </div>
</footer>
<!--footer-->


<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/jquery-3.2.1.js"></script>
<script>
    $.ajax({
        url: "allclub",
        type: "post",
        success: function (result) {
            for (var i in result) {
                //利用for循环给table添加行
                var club = result[i];
                addNewTR(club);
            }
        }
    })
    function addNewTR(club) {
        $("#user").append($("<tr><th scope=row>" + club.cid + "</th><td>" + club.cname + "</td>" +
                "<td>" + club.cintro + "</td><td><img src='"+club.cpic+"' onload='if (this.width>50 || this.height>50) if (this.width/this.height>50/50) this.width=50; else this.height=50;'/></td><td>" + club.cplace + "</td><td>" + club.cactivity + "</td>" +
                "<td><div role=presentation class=dropdown>" +
                "<button " + "class= btn-default btn dropdown-toggle" + " data-toggle=dropdown href=# role=button aria-haspopup=true aria-expanded=false>" +
                "操作<span class=caret></span>" +
                "</button>" + "<ul class=dropdown-menu> " +
                "<li><a href=delclub?cid="+club.cid+">删除</a></li> " +
                "<li><a href id='update' cid="+club.cid+" role=button data-toggle=modal data-target=#myModal onclick='update(this)'>修改</a></li></ul> " +
                "</div></td></tr>"));
    }

    function update(a) {
        var id = $(a).attr("cid")
        $.ajax({
            url:"selectclub",
            type:"post",
            data:{
                cid:id
            },
            success:function (result) {
                var club = result;
                $("#club").attr("action","/addclub?cid="+club.cid+"");
                $("#addname").val($("#addname").val()+club.cname);
                $("#addintro").val($("#addintro").val()+club.cintro);
                $("#addplace").val($("#addplace").val()+club.cplace);
                $("#addactivity").val($("#addactivity").val()+club.cactivity);
            }
        })
    }


</script>
</body>
</html>
